package com.bridgeintelligent.tag.customer.mapper;

import com.bridgeintelligent.tag.customer.entity.ShareRelation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description
 * @author: grp 2020-12-29 18:08
 **/
@Mapper
public interface CustomersShareMapper {
    @Select("SELECT user_id FROM TAG_CUSTOMERS_SHARE_RELATION where customers_id = #{customersId} and is_share = '01'")
    List<String> findByCustomersId(@Param("customersId")String customersId);

    int save(@Param("relations")List<ShareRelation> relation);

    int deleteByCustomersId(@Param("customersId")String customersId);

    int updIsShare(@Param("isShare")String isShare,@Param("cid")String cid,@Param("userIds")List<String> userIds);

    @Select("SELECT count(user_id) FROM TAG_CUSTOMERS_SHARE_RELATION where customers_id = #{cid} and is_share = '01'")
    int findExistByCid(@Param("cid")String cid);

    @Select("SELECT * FROM TAG_CUSTOMERS_SHARE_RELATION where customers_id = #{cid} and user_id = #{userId}")
    List<ShareRelation> findExistAllByCid(@Param("cid")String cid,@Param("userId")String userId);

    List<String> findExistByCidAndUid(@Param("cid")String cid,@Param("userIds")List<String> userIds);

    List<ShareRelation> findShareList(@Param("cid")String cid);

    @Select("SELECT shared_state FROM TAG_CUSTOMERS where customers_id = #{customersId}")
    String findShareStateByCustomersId(@Param("customersId")String customersId);
}
